package com.wisemoresystem.seal.action.seal.destroy;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_bank;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_over_log;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.service.SealDestroyService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章销毁 上缴
 * 
 * @author hxj
 */
@Controller("ixSealDestroyApply")
@Scope("prototype")
@RequestMapping("/ix/seal/destroy/apply")
public class SealDestroyApplyAction extends ProjBaseAction {

	@Autowired
	private SealDestroyService service;

	// t_seal flag_stop=上缴停用
	/**
	 * 印章销毁上缴列表
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = service.selectSealDestroyApplyList(
				WebTools.getCurrentBankId(), srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/destroy/apply/list");
		mv.addObject("list", list);
		return mv;
	}

	//
	/**
	 * 转到上缴页面
	 * 
	 * @param seal_id
	 *            印章id
	 * @return
	 */
	@RequestMapping("/over_form")
	public ModelAndView over_form(String seal_id) {

		t_seal seal = service.findObjById(seal_id, t_seal.class);

		ModelAndView mv = new ModelAndView("/jsp/seal/destroy/apply/over_form");
		mv.addObject("seal", seal);
		if (ChkTools.isNotNull(seal.getSeal_new_id())) {
			t_seal_new mac = service.findObjById(seal.getSeal_new_id(),
					t_seal_new.class);
			if (ChkTools.isNotNull(mac.getSeal_type_config_id())) {
				t_seal_type_config ma = service.findObjById(
						mac.getSeal_type_config_id(), t_seal_type_config.class);
				mv.addObject("ma", ma);
			}
			mv.addObject("mac", mac);
		}
		if (ChkTools.isNotNull(seal.getBank_id())) {
			t_bank bank = service.findObjById(seal.getBank_id(), t_bank.class);
			mv.addObject("bank", bank);
			t_bank superBank = service.findObjById(bank.getSuper_id(),
					t_bank.class);
			mv.addObject("superBank", superBank);
		}
		return mv;
	}

	// 上缴
	/**
	 * 印章上缴
	 * 
	 * @param seal_id
	 *            印章id
	 * @param over_log
	 *            上缴记录
	 * @return
	 */
	@RequestMapping("/over")
	public ModelAndView over(String seal_id, t_seal_over_log over_log) {

		if (service.over(seal_id, over_log)) {
			super.setTipMsg("上缴成功!", Tip.Type.success);
			logT.logH("印章上缴", t_seal.class, seal_id);
		} else {
			super.setTipMsg("上缴失败!", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

	/**
	 * 取消上缴操作
	 * 
	 * @param seal_id
	 *            印章id
	 * @return
	 */
	@RequestMapping("/cancle")
	public ModelAndView cancle(String seal_id) {

		if (service.cancleSeal(seal_id)) {
			this.setTipMsg("操作成功!", Tip.Type.success);
			logT.logH("取消印章上缴", t_seal.class, seal_id);
		} else {
			this.setTipMsg("操作失败!", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}
}
